package com.sky.repository;

import com.sky.entity.Book;
import org.bson.types.ObjectId;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface BookRepository extends MongoRepository<Book, String> {

    List<Book> findBytId(Integer tId);
    // 使用@Query实现单一关键词多字段搜索
    @Query("{ $or: [ " +
            "{ 'title': { $regex: ?0, $options: 'i' } }, " +
            "{ 'author': { $regex: ?0, $options: 'i' } } " +
            "] }")
    Page<Book> searchByKeyword(String keyword,Pageable pageable);

    @Query("{ '_id' : { '$in' : ?0 } }")
    List<Book> findByIds(List<String> ids);

}
